home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / config / obj-ecof.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-05  |  8.4 KB  |  255 lines

  1. /* ECOFF object file format.
  2.    Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  3.    Contributed by Cygnus Support.
  4.    This file was put together by Ian Lance Taylor <ian@cygnus.com>.
  5.  
  6.    This file is part of GAS.
  7.  
  8.    GAS is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2, or (at your option)
  11.    any later version.
  12.  
  13.    GAS is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with GAS; see the file COPYING.  If not, write to
  20.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. #include "as.h"
  23. #include "coff/internal.h"
  24. #include "bfd/libcoff.h"
  25. #include "bfd/libecoff.h"
  26.  
  27. /* Almost all of the ECOFF support is actually in ecoff.c in the main
  28.    gas directory.  This file mostly just arranges to call that one at
  29.    the right times.  */
  30.  
  31. /* These are the pseudo-ops we support in this file.  Only those
  32.    relating to debugging information are supported here.
  33.  
  34.    The following pseudo-ops from the Kane and Heinrich MIPS book
  35.    should be defined here, but are currently unsupported: .aent,
  36.    .bgnb, .endb, .verstamp, .vreg.
  37.  
  38.    The following pseudo-ops from the Kane and Heinrich MIPS book are
  39.    MIPS CPU specific, and should be defined by tc-mips.c: .alias,
  40.    .extern, .galive, .gjaldef, .gjrlive, .livereg, .noalias, .option,
  41.    .rdata, .sdata, .set.
  42.  
  43.    The following pseudo-ops from the Kane and Heinrich MIPS book are
  44.    not MIPS CPU specific, but are also not ECOFF specific.  I have
  45.    only listed the ones which are not already in read.c.  It's not
  46.    completely clear where these should be defined, but tc-mips.c is
  47.    probably the most reasonable place: .asciiz, .asm0, .endr, .err,
  48.    .half, .lab, .repeat, .struct, .weakext.  */
  49.  
  50. const pseudo_typeS obj_pseudo_table[] =
  51. {
  52.   /* COFF style debugging information. .ln is not used; .loc is used
  53.      instead.  */
  54.   { "def",    ecoff_directive_def,    0 },
  55.   { "dim",    ecoff_directive_dim,    0 },
  56.   { "endef",    ecoff_directive_endef,    0 },
  57.   { "file",    ecoff_directive_file,    0 },
  58.   { "scl",    ecoff_directive_scl,    0 },
  59.   { "size",    ecoff_directive_size,    0 },
  60.   { "esize",    ecoff_directive_size,    0 },
  61.   { "tag",    ecoff_directive_tag,    0 },
  62.   { "type",    ecoff_directive_type,    0 },
  63.   { "etype",    ecoff_directive_type,    0 },
  64.   { "val",    ecoff_directive_val,    0 },
  65.  
  66.   /* ECOFF specific debugging information.  */
  67.   { "begin",    ecoff_directive_begin,    0 },
  68.   { "bend",    ecoff_directive_bend,    0 },
  69.   { "end",    ecoff_directive_end,    0 },
  70.   { "ent",    ecoff_directive_ent,    0 },
  71.   { "fmask",    ecoff_directive_fmask,    0 },
  72.   { "frame",    ecoff_directive_frame,    0 },
  73.   { "loc",    ecoff_directive_loc,    0 },
  74.   { "mask",    ecoff_directive_mask,    0 },
  75.  
  76.   /* These are used on Irix.  I don't know how to implement them.  */
  77.   { "bgnb",    s_ignore,        0 },
  78.   { "endb",    s_ignore,        0 },
  79.   { "verstamp",    s_ignore,        0 },
  80.  
  81.   /* Sentinel.  */
  82.   { NULL }
  83. };
  84.  
  85. /* Swap out the symbols and debugging information for BFD.  */
  86.  
  87. void
  88. ecoff_frob_file ()
  89. {
  90.   const struct ecoff_debug_swap * const debug_swap
  91.     = &ecoff_backend (stdoutput)->debug_swap;
  92.   bfd_vma addr;
  93.   asection *sec;
  94.   HDRR *hdr;
  95.   char *buf;
  96.   char *set;
  97.  
  98.   /* Set the section VMA values.  We force the .sdata and .sbss
  99.      sections to the end to ensure that their VMA addresses are close
  100.      together so that the GP register can address both of them.  We
  101.      put the .bss section after the .sbss section.
  102.  
  103.      Also, for the Alpha, we must sort the sections, to make sure they
  104.      appear in the output file in the correct order.  (Actually, maybe
  105.      this is a job for BFD.  But the VMAs computed would be out of
  106.      whack if we computed them given our initial, random ordering.
  107.      It's possible that that wouldn't break things; I could do some
  108.      experimenting sometime and find out.
  109.  
  110.      This output ordering of sections is magic, on the Alpha, at
  111.      least.  The .lita section must come before .lit8 and .lit4,
  112.      otherwise the OSF/1 linker may silently trash the .lit{4,8}
  113.      section contents.  Also, .text must preceed .rdata.  These differ
  114.      from the order described in some parts of the DEC OSF/1 Assembly
  115.      Language Programmer's Guide, but that order doesn't seem to work
  116.      with their linker.
  117.  
  118.      I don't know if section ordering on the MIPS is important.  */
  119.  
  120.   static const char *const names[] = {
  121.     /* text segment */
  122.     ".text", ".rdata", ".init", ".fini",
  123.     /* data segment */
  124.     ".data", ".lita", ".lit8", ".lit4", ".sdata", ".got",
  125.     /* bss segment */
  126.     ".sbss", ".bss",
  127.   };
  128. #define n_names (sizeof (names) / sizeof (names[0]))
  129.  
  130.   addr = 0;
  131.   {
  132.     /* Sections that match names, order to be straightened out later.  */
  133.     asection *secs[n_names];
  134.     /* Linked list of sections with non-matching names.  Random ordering.  */
  135.     asection *other_sections = 0;
  136.     /* Pointer to next section, since we're destroying the original
  137.        ordering.  */
  138.     asection *next;
  139.  
  140.     int i;
  141.  
  142.     for (i = 0; i < n_names; i++)
  143.       secs[i] = 0;
  144.     for (sec = stdoutput->sections; sec != (asection *) NULL; sec = next)
  145.       {
  146.     next = sec->next;
  147.     for (i = 0; i < n_names; i++)
  148.       if (!strcmp (sec->name, names[i]))
  149.         {
  150.           secs[i] = sec;
  151.           break;
  152.         }
  153.     if (i == n_names)
  154.       {
  155.         bfd_set_section_vma (stdoutput, sec, addr);
  156.         addr += bfd_section_size (stdoutput, sec);
  157.         sec->next = other_sections;
  158.         other_sections = sec;
  159.       }
  160.       }
  161.     for (i = 0; i < n_names; i++)
  162.       if (secs[i])
  163.     {
  164.       sec = secs[i];
  165.       bfd_set_section_vma (stdoutput, sec, addr);
  166.       addr += bfd_section_size (stdoutput, sec);
  167.     }
  168.     for (i = n_names - 1; i >= 0; i--)
  169.       if (secs[i])
  170.     {
  171.       sec = secs[i];
  172.       sec->next = other_sections;
  173.       other_sections = sec;
  174.     }
  175.     stdoutput->sections = other_sections;
  176.   }
  177.  
  178.   /* Build the ECOFF debugging information.  */
  179.   assert (ecoff_data (stdoutput) != 0);
  180.   hdr = &ecoff_data (stdoutput)->debug_info.symbolic_header;
  181.   ecoff_build_debug (hdr, &buf, debug_swap);
  182.  
  183.   /* Finish up the ecoff_tdata structure.  */
  184.   set = buf;
  185. #define SET(ptr, count, type, size) \
  186.   if (hdr->count == 0) \
  187.     ecoff_data (stdoutput)->debug_info.ptr = (type) NULL; \
  188.   else \
  189.     { \
  190.       ecoff_data (stdoutput)->debug_info.ptr = (type) set; \
  191.       set += hdr->count * size; \
  192.     }
  193.  
  194.   SET (line, cbLine, unsigned char *, sizeof (unsigned char));
  195.   SET (external_dnr, idnMax, PTR, debug_swap->external_dnr_size);
  196.   SET (external_pdr, ipdMax, PTR, debug_swap->external_pdr_size);
  197.   SET (external_sym, isymMax, PTR, debug_swap->external_sym_size);
  198.   SET (external_opt, ioptMax, PTR, debug_swap->external_opt_size);
  199.   SET (external_aux, iauxMax, union aux_ext *, sizeof (union aux_ext));
  200.   SET (ss, issMax, char *, sizeof (char));
  201.   SET (ssext, issExtMax, char *, sizeof (char));
  202.   SET (external_rfd, crfd, PTR, debug_swap->external_rfd_size);
  203.   SET (external_fdr, ifdMax, PTR, debug_swap->external_fdr_size);
  204.   SET (external_ext, iextMax, PTR, debug_swap->external_ext_size);
  205.  
  206. #undef SET
  207.  
  208.   /* Fill in the register masks.  */
  209.   {
  210.     unsigned long gprmask = 0;
  211.     unsigned long fprmask = 0;
  212.     unsigned long *cprmask = NULL;
  213.  
  214. #ifdef TC_MIPS
  215.     /* Fill in the MIPS register masks.  It's probably not worth
  216.        setting up a generic interface for this.  */
  217.     gprmask = mips_gprmask;
  218.     cprmask = mips_cprmask;
  219. #endif
  220.  
  221. #ifdef TC_ALPHA
  222.     alpha_frob_ecoff_data ();
  223.  
  224.     if (! bfd_ecoff_set_gp_value (stdoutput, alpha_gp_value))
  225.       as_fatal ("Can't set GP value");
  226.  
  227.     gprmask = alpha_gprmask;
  228.     fprmask = alpha_fprmask;
  229. #endif
  230.  
  231.     if (! bfd_ecoff_set_regmasks (stdoutput, gprmask, fprmask, cprmask))
  232.       as_fatal ("Can't set register masks");
  233.   }
  234. }
  235.  
  236. /* This is called by the ECOFF code to set the external information
  237.    for a symbol.  We just pass it on to BFD, which expects the swapped
  238.    information to be stored in the native field of the symbol.  */
  239.  
  240. void
  241. obj_ecoff_set_ext (sym, ext)
  242.      symbolS *sym;
  243.      EXTR *ext;
  244. {
  245.   const struct ecoff_debug_swap * const debug_swap
  246.     = &ecoff_backend (stdoutput)->debug_swap;
  247.   ecoff_symbol_type *esym;
  248.  
  249.   know (bfd_asymbol_flavour (sym->bsym) == bfd_target_ecoff_flavour);
  250.   esym = ecoffsymbol (sym->bsym);
  251.   esym->local = false;
  252.   esym->native = xmalloc (debug_swap->external_ext_size);
  253.   (*debug_swap->swap_ext_out) (stdoutput, ext, esym->native);
  254. }
  255.